#!/usr/bin/env ts-node
import { PrismaClient, Prisma } from "@prisma/client";
import { faker } from "@faker-js/faker";
console.log("gender:", faker.name.gender());

const prisma = new PrismaClient();

const getUser = () => {
  const localTelephone = faker.phone.phoneNumber("188########");

  const localGender = () => {
    let gender = "";
    switch (faker.name.gender(true)) {
      case "Female":
        gender = "女";
        break;
      case "Male":
        gender = "男";
        break;
    }
    return gender
  };

  const localName = () => {
    faker.locale = "zh_CN";
    return faker.name.lastName() + faker.name.lastName();
  };

  const englishEmail = () => {
    faker.locale = "en";
    return faker.internet.email().toLowerCase();
  };

  return {
    telephone: localTelephone,
    password: faker.internet.password(6),
    name: localName(),
    gender: localGender(),
    email: englishEmail(),
    allowedPages: ["home", "setting"],
  };
};

async function main() {
  const users = new Array();
  for (let index = 0; index < 100; index++) {
    users.push(getUser());
    // console.log(getUser())
  }
  const createUser = await prisma.user.createMany({ data: users });
}

main()
  .catch((e) => {
    throw e;
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
